// JavaScript Document
//下拉刷新
var bp = {
	waterfall: function () {
		$(window).scroll(function () {
			//$(document).scrollTop() 获取垂直滚动的距离
			//$(document).scrollLeft() 这是获取水平滚动条的距离
			if ($(document).scrollTop() <= 0) {
				//console.log("滚动条已经到达顶部为0");
			}
			if ($(document).scrollTop() >= $(document).height() - $(window).height()) {
				//console.log("滚动条已经到达底部为" + $(document).scrollTop());
				getPage();
			}
		});
	},
	timestamp_to_date: function (time, type) {
		/* var timestamp4 = new Date(time);//直接用 new Date(时间戳) 格式转化获得当前时间
		//console.log(timestamp4);
		
		if (type == 1)
			return timestamp4.toLocaleDateString().replace(/\//g, "-");
		else
			return timestamp4.toLocaleDateString().replace(/\//g, "-") + " " + timestamp4.toTimeString().substr(0, 8); */
		var now = new Date(time);
		var year = now.getYear();
		var month = now.getMonth() + 1;
		var date = now.getDate();
		var hour = now.getHours();
		var minute = now.getMinutes();
		var second = now.getSeconds();
		if (type == 1)
			return year + "-" + month + "-" + date;
		else
			return year + "-" + month + "-" + date + "   " + hour + ":" + minute + ":" + second;
	},
	get_page: function (page) {
		var arr = page.split('.')
		return arr[0] + '.html';
	},
	jump: function (url) {
		if (url != 'null' && url != '') {
			window.location.href = CONFIG.siteUrl + bp.get_page(url);
		}
	}, page_light: {
		home: ['index.html', 'location.html'],
		type: ['typePage.html', 'shopList.html', 'details.html'],
		my: ['my.html', 'userInfo.html', 'shimingrz.html', 'qiyerz.html', 'collection.html', 'myAuction.html', 'bond.html', 'closingRecord.html', 'entrust1.html', 'auction.html'],
		more: ['helpCenter.html', 'jjjy.html', 'bondExplain.html', 'bidzige.html', 'weituo.html', 'about.html', 'problem.html', 'caozuozhinan.html']
	},
	in_array: function (stringToSearch, arrayToSearch) {
		stringToSearch = stringToSearch.split('?')[0];
		for (s = 0; s < arrayToSearch.length; s++) {
			thisEntry = arrayToSearch[s].toString();
			if (thisEntry == stringToSearch) {
				return true;
			}
		}
		return false;
	},
	//页面底部导航
	footer: function (page) {
		var uri_page = window.location.href.replace(window.location.origin + '/', '');
		var light = bp.in_array(uri_page, bp.page_light.home) ? 'f-nav-active' : '';
		htm = '<div onClick="bp.jump(\'index.html\')" class="f-nav ' + light + '">';
		htm += '    <div  class="navIcon homeIcon"></div>';
		htm += '    <div class="navTit">首页</div>';
		htm += '</div>';

		light = bp.in_array(uri_page, bp.page_light.type) ? 'f-nav-active' : '';
		htm += '<div onClick="bp.jump(\'typePage.html\')" class="f-nav ' + light + '">';
		htm += '    <div class="navIcon typeIcon"></div>';
		htm += '    <div class="navTit">分类</div>';
		htm += '</div>';
		light = bp.in_array(uri_page, bp.page_light.my) ? 'f-nav-active' : '';
		htm += '<div onClick="bp.jump_data(\'my.html\')" class="f-nav ' + light + '">';
		htm += '    <div class="navIcon myIcon"></div>';
		htm += '    <div class="navTit ">我</div>';
		htm += '</div>';

		light = bp.in_array(uri_page, bp.page_light.more) ? 'f-nav-active' : '';
		htm += '<div onClick="bp.jump(\'helpCenter.html\')" class="f-nav ' + light + ' ">';
		htm += '    <div class="navIcon moreIcon"></div>';
		htm += '    <div class="navTit">更多</div>';
		htm += '</div>';

		//console.log(page);
		if (page)
			$('footer').html(htm);
		else
			$('body').append('<footer>' + htm + '</footer>');
	},
	//页面后退
	goback: function () {
		history.back();
	}, jump_data: function (url) {
		if (url.indexOf('details.html') >= 0 || url.indexOf('my.html') >= 0) {
			$.setSession('jump_url', CONFIG.siteUrl + url);
			bp.user_info(function () {
				window.location.href = CONFIG.siteUrl + url;
			});
		} else {
			window.location.href = CONFIG.siteUrl + url;
		}
	}, get_data: function () {

		var url = location.search; //获取url中"?"符后的字串
		var theRequest = new Object();
		if (url.indexOf("?") != -1) {
			var str = url.substr(1);
			strs = str.split("&");
			for (var i = 0; i < strs.length; i++) {
				theRequest[strs[i].split("=")[0]] = (strs[i].split("=")[1]);
			}
		}
		return theRequest;
	}, check_mobile: function (mobile) {
		var err;
		if (!mobile) {
			err = "请输入手机号码";
		}
		err = err && err || (!(/^1\d{10}$/.test(mobile)) ? "请输入正确格式手机号码" : undefined);

		err && $.alert(err);
		return !err;
	}, upload: function readFile() {
		var fd = new FormData();
		fd.append('fileType', 'personal');
		for (var i = 0; i < this.files.length; i++) {
			if (!input['value'].match(/.jpg|.jpeg|.png|.bmp|.JPG|.JPEG|.PNG|.BMP/i)) {　　//判断上传文件格式
				return $.layermsg("上传的图片格式不正确，请重新选择");
			}
			if (this.files[i].size > 20 * 1024 * 1024) {  //用size属性判断文件大小不能超过20M
				$.layermsg("你上传的文件太大了");
				return false;
			}
			var reader = new FileReader();
			reader.readAsDataURL(this.files[i]); //调用readAsDataURL方法来读取选中的图像文件
			fd.append(i, this.files[i]);
			$.ajax({
				url: CONFIG.apiUrl + '/upload/documentByH5.api',
				type: 'post',
				data: fd,
				processData: false,
				contentType: false,
				beforeSend: function () {
					if (layer)
						layer.closeAll('loading');
					$.layerload();
				},
				success: function (res) {
					if (layer)
						layer.closeAll('loading');
					if (res.code && res.code != 200) {
						$.layermsg(res.msg);
						return false;
					}
					var fileList = res.data;
					if (null == fileList || fileList.length == 0) {
						$.layermsg("文件上传失败");
						return false;
					}
					var urlZ = fileList[0].path;
					$("#" + _id).siblings("img").attr("src", CONFIG.imgUrl + urlZ);
					$("#" + _id).siblings("img").attr("filePath", urlZ);
					$("#" + _id).addClass("alphaClass");
					$("#" + _id).siblings("span").addClass("alphaClass");
					F
				},
				error: function () {
					if (layer)
						layer.closeAll('loading');
					$.layermsg("图片上传异常，请重试");
				}
			})
		}
	}, user_info: function (callback) {
		var data = {};
		$.commonAjax({
			url: 'B039',
			type: 'POST',
			data: data,
			isShowError: true,
			success: function (res) {
				var data = res.data
				callback();
			}, error: function (res) {
				$.layermsg(res.msg);
			}
		});
	},
	data_to_str: function (data) {
		var str = '';
		$.each(data, function (k, y) {
			str += k + ':' + (y ? y : 0) + ',';
		});
		str = str.substring(0, str.length - 1);
		return str;
	}, json_length: function (json) {
		var num = 0;
		$.each(json, function (k, v) {
			num++
		});
		return num;
	}

}
var num = 0;
$(function () {
	$('.backArrow').click(function () {
		bp.goback();
	});
	bp.footer();
});